<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/9
 * Time: 10:12
 */
session_start();
$username =$_POST['username'];
$oldpassword =$_POST['oldpassword'];
$newpassword =$_POST['newpassword'];

$key =$_COOKIE['userkey'];
if ($key==md5($username.$oldpassword)){
    if ($newpassword==$oldpassword){
        echo '新旧密码不能一致，请修改新密码';

    }else{
        $key =md5($username.$newpassword);
        setcookie('userkey',$key,time()+24*3600,'/');
        $_SESSION[$key]=[
            'username'=>$username,
            'password'=>$newpassword
        ];
    echo '修改成功<a href="../login.php">重新登陆</a>';
    }
}else{
    echo '旧密码或用户名错误！';
}